﻿using System;
using Samurai.Validation;

namespace Samurai.Workflow
{
    public interface IWorkflow<T> where T : class, IWorkflowContext
    {
        /// <summary>
        /// Occurs when the final step in the workflow has completed.
        /// </summary>
        event EventHandler<WorkflowCompletedEventArgs<T>> WorkflowCompleted;

        /// <summary>
        /// Occurs when a step in the workflow fails.
        /// </summary>
        event EventHandler<WorkflowCompletedEventArgs<T>> WorkflowFailed;

        /// <summary>
        /// Gets or sets the context which to pass along the workflow as it executes.
        /// </summary>
        /// <value>The context.</value>
        T Context { get; set; }

        /// <summary>
        /// Gets or sets the context validator.
        /// </summary>
        /// <value>The context validator.</value>
        IValidator<T> ContextValidator { get; set; }

        /// <summary>
        /// Gets the number of actions registered in the workflow.
        /// </summary>
        /// <value>The count.</value>
        int Count { get; }

        /// <summary>
        /// Clears all registered actions from the workflow.
        /// </summary>
        void Clear();

        /// <summary>
        /// Starts the workflow by executing the first step.
        /// </summary>
        void Start();

        /// <summary>
        /// Stops the workflow execution and raises WorkflowCompleted event.
        /// </summary>
        void Stop();
    }
}
